#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    numStr = ui->lineEdit->text();
    bool b = false;
    if(numStr != NULL && numStr.size()>0)
    {
        uint num = numStr.toUInt(&b,10);
        if(b)
        {
            qDebug() << "转换成十进制成功！" << endl;
            QString value;
            value.setNum(num,10);
            ui->lineEdit_2->setText(value);
        }
        else
        {
            qDebug() << "转换成十进制失败" << endl;
        }
    }
}

void MainWindow::on_pushButton_2_clicked()
{
    numStr = ui->lineEdit->text();
    bool b = false;
    if(numStr != NULL && numStr.size()>0)
    {
        uint num = numStr.toUInt(&b,10);
        if(b)
        {
            qDebug() << "转换成二进制成功！" << endl;
            QString value;
            value.setNum(num,2);
            ui->lineEdit_3->setText(value);
        }
        else
        {
            qDebug() << "转换成二进制失败" << endl;
        }
    }
}

void MainWindow::on_pushButton_3_clicked()
{
    numStr = ui->lineEdit->text();
    bool b = false;
    if(numStr != NULL && numStr.size()>0)
    {
        uint num = numStr.toUInt(&b,10);
        if(b)
        {
            qDebug() << "转换成十六进制成功！" << endl;

            QString value;
            value.setNum(num,16);
            ui->lineEdit_4->setText(value.toUpper());
        }
        else
        {
            qDebug() << "转换成十六进制失败" << endl;
        }
    }
}
